home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / spxcht.arc / SENDSPX.C < prev    next >
C/C++ Source or Header  |  1988-02-01  |  6KB  |  190 lines

  1. #include <stdio.h>
  2. #include <nit.h>
  3. #include "bill.h"
  4.  
  5. long  stats=0;
  6.  
  7. unsigned int  Socket=0x5555;
  8. int        ConnectionID;
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     int        ccode, ConnectionNumber, TransportTime, i=0;
  15.     ECBStructure    *ConnectionECB, *SendECB, *PoolECB;
  16.     SPXStructure    *ConnectionSPX, *SendSPX, *PoolSPX;
  17.     char far        *farcharpointer;
  18.     char             *data, *ReadData;
  19.     void  ReceiveESRHandler();
  20.     void  SendESRHandler();
  21.  
  22.     printf("What is the Connection Number of the station you are sending to:  ");
  23.     ConnectionNumber = atoi(gets());
  24.  
  25.     IPXInitialize();
  26.  
  27.     if ((ccode = IPXOpenSocket(&Socket, 0x00)) != 0) {
  28.         printf("The socket was not opened ");
  29.         exit(-1);
  30.     }
  31.     /* ****************************************************************** */
  32.     while (i++ != 5) {
  33.         if ((PoolECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL ) {
  34.             printf("Out of memory trying to allocate for the PoolECB\n ");
  35.             exit(-1);
  36.         }
  37.         if ((PoolSPX = (SPXStructure *)myalloc(1, sizeof(SPXStructure))) == NULL ) {
  38.             printf("Out of memory trying to allocate for the PoolSPX\n ");
  39.         }
  40.         data = (char *)myalloc(1, 2);
  41.         ReadData = (char *)myalloc(1, 2);
  42.  
  43.  
  44.         farcharpointer = (char far *)ReceiveESRHandler;
  45.         PoolECB->ESRAddress = farcharpointer;
  46.         PoolECB->ECBSocket = Socket;
  47.         PoolECB->FragmentCount = 2;
  48.         farcharpointer = (char far *)PoolSPX;
  49.         PoolECB->FragmentDescriptor[0].Address = farcharpointer;
  50.         PoolECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
  51.         farcharpointer = (char far *)data;
  52.         PoolECB->FragmentDescriptor[1].Address = farcharpointer;
  53.         PoolECB->FragmentDescriptor[1].Size = 2;
  54.         PoolSPX->PacketType = (char)5;
  55.         PoolSPX->PacketLength = IntSwap( sizeof(SPXStructure));
  56.  
  57.         SPXListenForSequencedPacket(PoolECB);
  58.     }
  59.     /* **************************************************************** */
  60.  
  61.     if ((ConnectionECB = (ECBStructure *)myalloc(1,sizeof(ECBStructure))) == NULL) {
  62.         printf("Out of memory for allocating ConnectionECB\n");
  63.  
  64.         
  65.         
  66.         
  67.         exit(-1);
  68.         }
  69.     if ((ConnectionSPX = (SPXStructure *)myalloc(1,sizeof(SPXStructure))) == NULL) {
  70.         printf("Out of memory for allocating ConnectionSPX\n");
  71.         exit(-1);
  72.         }
  73.     ConnectionSPX->PacketLength = IntSwap(sizeof(SPXStructure));
  74.     ConnectionSPX->PacketType   = 5;
  75.     ConnectionSPX->Destination.Socket = Socket;
  76.     ConnectionECB->ECBSocket = Socket;
  77.     ConnectionECB->FragmentCount = 1;
  78.     farcharpointer = (char far *)ConnectionSPX;
  79.     ConnectionECB->FragmentDescriptor[0].Address = farcharpointer;
  80.     ConnectionECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
  81.  
  82.     MapConnectionNumberToAddress((unsigned char)ConnectionNumber,
  83.         ConnectionSPX->Destination.Network, ConnectionSPX->Destination.Node);
  84.     
  85.     IPXGetLocalTarget( (unsigned char *)ConnectionSPX->Destination.Network,
  86.         (unsigned char *)ConnectionECB->ImmediateAddress, TransportTime);
  87.  
  88.     ccode = SPXEstablishConnection( (char)5, (char)0, (int *)&ConnectionID,
  89.         ConnectionECB);
  90.     if (ccode) {
  91.         printf("Connection was not made\n");
  92.         exit(-1);
  93.     }
  94.     while (ConnectionECB->InUse) {
  95.         IPXRelinquishControl();
  96.     }
  97.     switch (ConnectionECB->CompletionCode) {
  98.     case 0x00:
  99.         printf("Connection ID is:   %x\n",ConnectionID);
  100.         break;
  101.     case 0xED:
  102.         printf("No connection established..was receiver ready?\n");
  103.         break;
  104.     default:
  105.         printf("Error during establish connection \n");
  106.         break;
  107.     }
  108.     /* ***************************************************************** */
  109.     if ((SendECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
  110.         printf("Out of memory for allocation to SendECB\n");
  111.         exit(-1);
  112.     }
  113.     if ((SendSPX = (SPXStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
  114.         printf("Out of memory for allocation to SendSPX\n");
  115.         exit(-1);
  116.         }
  117.     data = (char *)myalloc(1, 2);
  118.  
  119.     strcpy(data,"xxxxxxxx");
  120.     farcharpointer = (char far *)SendESRHandler;
  121.     SendECB->ESRAddress = farcharpointer;
  122.     SendECB->ECBSocket = Socket;
  123.     SendECB->FragmentCount = 2;
  124.     farcharpointer = (char far *)SendSPX;
  125.     SendECB->FragmentDescriptor[0].Address = farcharpointer;
  126.     SendECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
  127.     farcharpointer = (char far *)data;
  128.     SendECB->FragmentDescriptor[1].Address = farcharpointer;
  129.  
  130.     
  131.     
  132.     
  133.     SendECB->FragmentDescriptor[1].Size = 2;
  134.     SendSPX->PacketType = (char)5;
  135.     SendSPX->PacketLength = IntSwap(sizeof(SPXStructure));
  136.  
  137.     MapConnectionNumberToAddress((unsigned char)ConnectionNumber,
  138.         SendSPX->Destination.Network, SendSPX->Destination.Node);
  139.  
  140.     IPXGetLocalTarget( (unsigned char *)SendSPX->Destination.Network,
  141.         (unsigned char *)SendECB->ImmediateAddress, TransportTime);
  142.  
  143.     SendSPX->Destination.Socket = Socket;
  144.  
  145.     printf("Hit any key to continue \n");
  146.     *ReadData = 0xFF;
  147.     while (strcmp(*ReadData,(char)0x1B) != 0) {
  148.         *ReadData = getch();
  149.         if (strcmp(*ReadData,(char)0x1B) != 0)
  150.             printf("%c",*ReadData);
  151.         if (strcmp(*ReadData,(char)0x0D) == 0)
  152.             printf("\n");
  153.         farcharpointer = (char far *)ReadData;
  154.         SendECB->FragmentDescriptor[1].Address = farcharpointer;
  155.  
  156.         SPXSendSequencedPacket(ConnectionID,SendECB);
  157.         while (SendECB->InUse)
  158.             IPXRelinquishControl();
  159.         switch (SendECB->CompletionCode) {
  160.         case 0x00:
  161.             break;
  162.         case 0xED:
  163.             printf("\n\nConnection failed \n");
  164.             exit(-1);
  165.             break;
  166.         case 0xEE:
  167.             printf("\n\nConnection terminated from other side\n ");
  168.             exit(0);
  169.             break;
  170.         default:
  171.             printf("Error occured while trying to send \n");
  172.             exit(-1);
  173.             break;
  174.         }
  175.     }
  176.  
  177. }
  178.  
  179. void SendESR(ESR_ECB)
  180. ECBStructure    *ESR_ECB;
  181. {
  182.     stats++;
  183. }
  184.  
  185. void ReceiveESR(ESR_ECB)
  186. ECBStructure     *ESR_ECB;
  187. {
  188.     SPXListenForSequencedPacket(ESR_ECB);
  189. }
  190.